<template>
	<view>
		<myhead left="1"></myhead>
		<view class="tit">提币</view>
		<view class="bz">USDT</view>
		<view class="inputList">
		    <view class="title">提币地址</view>
		    <input placeholder="点击选择提币地址" disabled v-model="address" @tap="cardBtn"></input>
		</view>
		<view class="inputList">
		    <view class="title">提币数量</view>
			<span class="tbNum">
				<input :value="num" v-model="num" placeholder="请输入提币数量"></input>
				<view @tap='qbBtn' class="qbBtn">全部</view>
			</span>
		</view>
		<view class="inputList">
		    <view class="title">手续费</view>
		    <view class="sxf">
		    	<view>{{sxf}}</view>
				<view>USDT</view>
		    </view>
		</view>
		<view class="inputList">
			<view class="sxf">
				<view>到账数量</view>
				<view>{{num}}USDT</view>
			</view>
			<view class="qdBtn" @tap="tbBtn">确定</view>
		</view>
	</view>
</template>

<script>
	const http = require('../../utils/http.js');
	export default {
		data() {
			return {
				num:null,
				sxf:null,
				address:null,
				cardId:null,
				cardListTxt:[],
			}
		},
		onShow() {
			uni.showLoading({
			    title: '加载中'
			});
			http.get('/api/user/getProfit').then(res => {
				//console.log(res)
				if (res.code == 200) {
					this.sxf=res.result
					http.get('/api/user/getMyAddress').then(res1 => {
						if (res1.code == 200 && res1.result) {
							this.cardList=res1.result
							for(var i=0;i<res1.result.length;i++){
								this.cardListTxt[i]=res1.result[i].remark
								if(this.cardId==res1.result[i].id){
									this.address=res1.result[i].remark
								}
							}
						}
					})
				}
				uni.hideLoading();
			})
		},
		methods: {
			cardBtn:function(){
				let that=this
				//console.log(that.cardListTxt)
				var cardList=that.cardList
				if(that.cardList.length){
					uni.showActionSheet({
					    itemList: that.cardListTxt,
					    success: function (res) {
					        //console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
							that.address=that.cardList[res.tapIndex].address
							that.cardId=cardList[res.tapIndex].id
							console.log(that.cardId)
					    },
					    fail: function (res) {
					        console.log(res.errMsg);
					    }
					});
				}else{
					uni.showToast({
					  title: '请到安全中心USDT地址管理添加',
					  icon: 'none'
					});
				}
			},
			qbBtn:function(){
				http.get('/api/user/getUseableAmount').then(res => {
					//console.log(res)
					if (res.code == 200) {
						this.num=res.result
					}
				})
			},
			tbBtn:function(){
				if(!this.address){
					uni.showToast({
					  title: '请输入提币地址',
					  icon: 'none',
					  duration:1000
					});
					return false
				}
				if(!this.num){
					uni.showToast({
					  title: '请输入提币数量',
					  icon: 'none',
					  duration:1000
					});
					return false
				}
				http.get('/api/user/outAmount',{addressId:this.cardId,useableAmount:this.num}).then(res => {
					//console.log(res)
					if (res.code == 200) {
						this.num=res.result
					}
					uni.showToast({
					  title: res.message,
					  icon: 'none',
					  duration:5000
					});
				})
			}
		}
	}
</script>

<style>
	page{
		background: #F5F8FF;
	}
	.tit{
		padding: 6vw 4vw;
		font-size: 7vw;
		color: #333333;
	}
	.bz{
		width: 84%;
		background: #FFFFFF;
		color: #333333;
		padding: 6vw 4vw;
		margin: 0 auto;
		border-radius: 2vw;
		margin-bottom: 6vw;
	}
	.inputList{
		padding: 0 8vw;
		margin-bottom: 6vw;
	}
	.inputList .title{
		margin-bottom: 2vw;
		font-size: 3.6vw;
		color: #999999;
	}
	.inputList input{
		height: 12vw;
		line-height: 12vw;
		border-bottom: 1px solid #F2F2F2;
	}
	.tbNum{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.tbNum input{
		width: 80%;
	}
	.qbBtn{
		width: 20%;
		text-align: center;
		color: #24EBA9;
		font-size: 3.8vw;
	}
	.sxf{
		height: 12vw;
		line-height: 12vw;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
	.qdBtn{
		width: 100%;
		padding: 4vw 0;
		font-size: 3.5vw;
		border-radius: 1.8vw;
		background-image: linear-gradient(45deg, #24EBA9, #10C7B2);
		color: #FFFFFF;
		text-align: center;
		margin: 0 auto;
	}
</style>
